package com.ap.core.bulkupload.translator;

import java.math.BigInteger;

import org.joda.time.LocalDateTime;

import com.ap.core.bulkupload.jaxb.domain.DistributorIdType;
import com.ap.core.bulkupload.jaxb.domain.FileHdrType;
import com.ap.core.bulkupload.jaxb.domain.Merchant;
import com.ap.core.bulkupload.jaxb.domain.MerchantRegBulkUploadResponseType;
import com.ap.core.bulkupload.jaxb.domain.ResponseFileHdrType;
import com.ap.core.bulkupload.jaxb.domain.ResponseType;

/**
 * The Class BulkUploadMerchantResponseTranslatorImpl.
 * @author Siva.Pochana
 */
public class BulkUploadMerchantResponseTranslatorImpl implements
		BulkUploadMerchantResponseTranslator {

	/** The response file hdr type. */
	private ResponseFileHdrType responseFileHdrType;
	
	/** The distributor id type. */
	private DistributorIdType distributorIdType;
	
	/** The noof rec updtd. */
	private int noofRecUpdtd;
	
	/** The noof rec upd fld. */
	private int noofRecUpdFld;
	
	/* (non-Javadoc)
	 * @see com.ap.core.bulkupload.translator.BulkUploadMerchantResponseTranslator#buildResponse()
	 */
	@Override
	public MerchantRegBulkUploadResponseType buildResponse() {
		MerchantRegBulkUploadResponseType merchantBulkUploadResponseType = new MerchantRegBulkUploadResponseType();
		
		merchantBulkUploadResponseType.setFileHdr(responseFileHdrType);
		merchantBulkUploadResponseType.setDistributorId(distributorIdType);
		
		ResponseType responseType = new ResponseType();
		responseType.setNoofRecFld(BigInteger.valueOf(noofRecUpdFld));
		responseType.setNoofRecUpdtd(BigInteger.valueOf(noofRecUpdtd));
		merchantBulkUploadResponseType.setResponse(responseType);
		
		return merchantBulkUploadResponseType;
	}

	/* (non-Javadoc)
	 * @see com.ap.core.bulkupload.translator.BulkUploadMerchantResponseTranslator#setFileHeader(com.ap.core.bulkupload.jaxb.domain.FileHdrType)
	 */
	@Override
	public void setFileHeader(FileHdrType fileHdrType) {
		this.responseFileHdrType = new ResponseFileHdrType();
		this.responseFileHdrType.setMsgTimestamp(new LocalDateTime());
		this.responseFileHdrType.setOrgFileId(fileHdrType.getFileId());
	}

	/* (non-Javadoc)
	 * @see com.ap.core.bulkupload.translator.BulkUploadMerchantResponseTranslator#setDistributor(com.ap.core.bulkupload.jaxb.domain.DistributorIdType)
	 */
	@Override
	public void setDistributor(DistributorIdType distributorIdType) {
		this.distributorIdType = distributorIdType;

	}

	/* (non-Javadoc)
	 * @see com.ap.core.bulkupload.translator.BulkUploadMerchantResponseTranslator#setMerchant(com.ap.core.bulkupload.jaxb.domain.Merchant, boolean)
	 */
	@Override
	public void setMerchant(Merchant merchant, boolean isRegistered) {
		if(isRegistered) {
			this.noofRecUpdtd = this.noofRecUpdtd + 1;
		} else {
			this.noofRecUpdFld = this.noofRecUpdFld + 1;
		}
	}

}
